home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / ptv1n1.arc / L3.ASM < prev    next >
Assembly Source File  |  1990-06-08  |  2KB  |  69 lines

  1. ;
  2. ; *** Listing 3 ***
  3. ;
  4. ; Assembler subroutine to perform a 16-bit checksum on the file
  5. ; opened on the passed-in handle. Stores the result in the
  6. ; passed-in checksum variable. Returns 1 for success, 0 for error.
  7. ;
  8. ; Call as:
  9. ;    int ChecksumFile(unsigned int Handle, unsigned int *Checksum);
  10. ;
  11. ; where:
  12. ;    Handle = handle # under which file to checksum is open
  13. ;    Checksum = pointer to unsigned int variable checksum is
  14. ;        to be stored in
  15. ;
  16. ; Parameter structure:
  17. ;
  18. Parms    struc
  19.         dw    ?    ;pushed BP
  20.         dw    ?    ;return address
  21. Handle        dw    ?
  22. Checksum    dw    ?
  23. Parms    ends
  24. ;
  25.     .model small
  26.     .data
  27. TempWord label    word
  28. TempByte db    ?        ;each byte read by DOS will be
  29.                 ; stored here
  30.     db    0        ;high byte of TempWord is always 0
  31.                 ; for 16-bit adds
  32. ;
  33.     .code
  34.     public _ChecksumFile
  35. _ChecksumFile    proc    near
  36.     push    bp
  37.     mov    bp,sp
  38.     push    si        ;save C's register variable
  39. ;
  40.     mov    bx,[bp+Handle]    ;get file handle
  41.     sub    si,si        ;zero the checksum accumulator
  42.     mov    cx,1        ;request one byte on each read
  43.     mov    dx,offset TempByte ;point DX to the byte in which
  44.                 ; DOS should store each byte read
  45. ChecksumLoop:
  46.     mov    ah,3fh        ;DOS read file function #
  47.     int    21h        ;read the byte
  48.     jc    ErrorEnd    ;an error occurred
  49.     and    ax,ax        ;any bytes read?
  50.     jz    Success        ;no-end of file reached-we're done
  51.     add    si,[TempWord]    ;add the byte into the checksum total
  52.     jmp    ChecksumLoop
  53. ErrorEnd:
  54.     sub    ax,ax        ;error
  55.     jmp    short Done
  56. Success:
  57.     mov    bx,[bp+Checksum] ;point to the checksum variable
  58.     mov    [bx],si        ;save the new checksum
  59.     mov    ax,1        ;success
  60. ;
  61. Done:
  62.     pop    si        ;restore C's register variable
  63.     pop    bp
  64.     ret
  65. _ChecksumFile    endp
  66.     end
  67.  
  68.  
  69.